package org.springblade.modules.material.strategy.impl;

import org.springblade.common.enums.library.QuestionType;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.library.vo.QuestionOptionVO;
import org.springblade.modules.material.entity.PaperAnswerEntity;
import org.springblade.modules.material.entity.PaperAnswerOptionEntity;
import org.springblade.modules.material.strategy.CalculateScoreStrategy;
import org.springblade.modules.material.vo.PaperAnswerVO;
import org.springblade.modules.material.vo.PaperDetailsRelatedVO;
import org.springblade.modules.material.vo.PaperReleaseDetailVO;

import java.util.List;

/**
 * @Author: junxin
 * @Description: 计算填空题
 */
public class CalculateClozeQuestion implements CalculateScoreStrategy {

	@Override
	public Integer calculateScore(List<PaperReleaseDetailVO> paperReleaseDetailVOList,
								  List<PaperAnswerOptionEntity> paperAnswerOptionEntityList, Long paperAnswerId, Integer multipleScoreSetting) {
		int score = 0;
		for (PaperReleaseDetailVO paperReleaseDetailVO : paperReleaseDetailVOList) {
			//选项内容
			List<QuestionOptionVO> questionOptionList = paperReleaseDetailVO.getQuestionOptionList();
			for (QuestionOptionVO questionOptionVO : questionOptionList) {
				PaperAnswerOptionEntity paperAnswerOptionEntity = new PaperAnswerOptionEntity();
				paperAnswerOptionEntity.setAnswerId(paperAnswerId);
				paperAnswerOptionEntity.setUserId(AuthUtil.getUserId());
				paperAnswerOptionEntity.setAnswerContent(questionOptionVO.getAnswerContent());//设置回答内容
				paperAnswerOptionEntity.setReleaseDetailId(paperReleaseDetailVO.getId());
				paperAnswerOptionEntity.setValue(0);
				paperAnswerOptionEntity.setQuestionId(questionOptionVO.getQuestionBankId());
				if (questionOptionVO.getOption().equals(questionOptionVO.getAnswerContent())) {
					score += paperReleaseDetailVO.getValue();//每填对一个空都可得一次这个分数
					paperAnswerOptionEntity.setQuestionType(QuestionType.FILL.getCode());
					paperAnswerOptionEntity.setValue(paperReleaseDetailVO.getValue());
				}
				paperAnswerOptionEntityList.add(paperAnswerOptionEntity);
			}
		}

		return score;
	}
}
